package com.example.synthesize.多线程.同步工具类countdownlatch;
import lombok.AllArgsConstructor;
import java.time.LocalTime;
import java.util.Random;
import java.util.concurrent.CountDownLatch;

/**
 * Created by IntelliJ IDEA2022.3.2
 * @Author: Tenghw
 * @Date: 2023/03/21  13:26
 * @Description: 顾客类
 */
@AllArgsConstructor
public class Consumer implements Runnable{
    private CountDownLatch latch;
    private String name;

    @Override
    public void run() {
        try {
            Random random = new Random();
            System.out.println(LocalTime.now()+" : " +name+ "出发去了饭店");
            Thread.sleep((long)(random.nextInt(10)*1000));
            System.out.println(LocalTime.now()+" : " +name+ "到达了饭店！");
            latch.countDown();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
